package com.example.imitation_webchat_demo.adapter;

import java.util.List;

import com.example.imitation_webchat_demo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

//设置页面所对应的适配器类
public class SettingAdapter extends BaseAdapter {
	private Context context;
	private List<String> list;
	
	public SettingAdapter(Context context, List<String> list){
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if(convertView == null){
			convertView = LayoutInflater.from(context).inflate(R.layout.setting_item, null);
			TextView textView = (TextView) convertView.findViewById(R.id.setting_item_textview);
			viewHolder = new ViewHolder(textView);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.textView.setText(list.get(position));
		return convertView;
	}

	private class ViewHolder{
		TextView textView;

		public ViewHolder(TextView textView) {
			this.textView = textView;
		}
	}
}